package 图书系统.user.operation;

import 图书系统.user.book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("<删除书籍>");
        System.out.println("请输入你要删除的书名");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int i=0;
        for (;i < bookList.getCount(); i++) {
            if(name.equals(bookList.getArr(i).getName())){
                break;
            };
        }
        if(i>=bookList.getCount()){
            System.out.println("没有找到你要删的书籍！");
        }else {
            //删除书籍操作
            for (int j = i; j <bookList.getCount() ; j++) {
                bookList.setArr(j,bookList.getArr(j+1));
            }
            //减一本
            bookList.setCount(bookList.getCount()-1);
        }
    }
}
